#include "widget.h"
#include "ui_widget.h"
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    connect(ui->pushButton, &QPushButton::clicked, this, &Widget::handleClick1);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::handleClick1()
{
    this->setWindowTitle("标题一");
    qDebug() << "click1";
}

void Widget::handleClick2()
{
    this->setWindowTitle("标题二");
    qDebug() << "click2";
}


void Widget::on_pushButton_2_clicked()
{
    // 想要让一个信号与另一个槽连接的时候，
    // 需要先取消之前连接的槽
    disconnect(ui->pushButton, &QPushButton::clicked, this, &Widget::handleClick1);
    connect(ui->pushButton, &QPushButton::clicked, this, &Widget::handleClick2);
}
